<?php
class PaymentAmazonCard extends PaymentData {

	const NAME 			= 'amazoncard';
	const SCENE_SHOW 	= 'show'; 
	
	protected $_productAr;
	
	protected $_amazoncard;
	
	public $amazoncardId = 0;

	public function __construct(){
		$this->setName(self::NAME);
	}

	public function amazoncardInfo(){
		return $this->_amazoncard;
	}

	public function getAmzonCard($amazonIndex){
		switch ($amazonIndex) {
			case ($amazonIndex instanceof PaymentAuctions):
					$temp	= Products::model()->with('amazonProduct','amazonProduct.productImage')->find(array('select' => 't.id','condition' => 't.id =:amazonId','params' => array(':amazonId'=>$amazonIndex->product_id)));					
					if (!empty($temp) && !empty($temp->amazonProduct)){
						$this->_amazoncard 		= $temp->amazonProduct;
						$this->amazoncardId		= $this->_amazoncard->amazonProduct->id;
					}
				break;
			case (is_numeric($amazonIndex)):
					$this->_amazoncard 	= Products::model()->with('productImage')->find(' t.id = :amazonId AND t.enable = '.ConstService::ENABLE.' AND t.replacement = '.ConstService::ENABLE,array(':amazonId' => $amazonIndex));	
					if (!empty($this->_amazoncard)){
						$this->amazoncardId  = $this->_amazoncard->id;
					}
				break;
			default:
					$this->_amazoncard 	= false;			
		}
		return $this;
	}

	public function vaild(){
		switch ($this->scene){
			case 'default':
								
				if (empty($this->amazoncardId)){
					$this->setErrorMessage('amazoncardId','amazon card Id not ');
					return $this->vaild;
				}
				
				$this->getAmzonCard($this->amazoncardId);
				
				if (empty($this->_amazoncard)){
					$this->setErrorMessage('amazoncard','amazon card not ');
				}
				
				break;				
			case 'show':
				
				break;
		}
		return $this->vaild;
	}
	
	public function toArray(){
		return array(
			'amazoncardId'	=> $this->amazoncardId
		);
	}
}
